<?php
/**
 * @version		$Id: default.php 17130 2010-05-17 05:52:36Z eddieajau $
 * @package		Joomla.Site
 * @subpackage	com_content
 * @copyright	Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 */

// no direct access
defined('_JEXEC') or die;

JHtml::_('behavior.mootools');

$get = JRequest::get('get');

$isSearchAdvance = false;

if( !empty($get['catid']) || !empty($get['org_id']) || !empty($get['type_id']) || !empty($get['kind_id']) )
	$isSearchAdvance = true;
?>


<script type="text/javascript">
<!--
	window.addEvent('domready', function(){
		$('td-advance-search').addEvent('click', function(){
			$('table-advance-search').toggle();
			$('tr-simple-search').toggle();
		});

		$$('#btn-simple-search', '#btn-advance-search').addEvent('click', function(){
			$('frm-text-search').submit();
		});
	});
//-->
</script>

<form name="frm-text-search" id="frm-text-search" method="get" action="<?php echo juri::base(); ?>index.php">

<input type="hidden" name="option" value="com_skkn" />

<table width="100%" cellpadding="3" cellspacing="0" id="text-table-search">
	<tr>
		<td class="table-heading">Tìm kiếm văn bản</td>
	</tr>
	<tr>
		<td class="tracuu" style="padding:10px;">
			<table width="100%" cellpadding="5" cellspacing="0">		
				<tr>
					<td width="200">Số hiệu văn bản</td>
					<td><input type="text" value="<?php echo @$get['text_code']; ?>" name="text_code" /></td>
				</tr>
				<tr>
					<td>Ngày ban hành</td>
					<td><input type="text" value="<?php echo @$get['text_created']; ?>" name="text_created" /><br>
						<small>(Nhập theo định đạng: DD/MM/YYYY)</small></td>
				</tr>
				<tr>
					<td>Hiệu lực</td>
					<td><input type="checkbox" value="1" name="still_valid" class="checkbox" <?php if( @$get['still_valid'] == 1 || !isset($get['is_search']) ):?>checked<?php endif;?> /> Còn hiệu lực</td>
				</tr>
				<tr>
					<td>Trích yếu</td>
					<td><input type="text" value="<?php echo @$get['description']; ?>" name="description" /></td>
				</tr>
				<?php if(!$isSearchAdvance): ?>
				<tr id="tr-simple-search">
					<td></td>
					<td><input class="button" type="button" value="Tìm kiếm" id="btn-simple-search" /></td>
				</tr>
				<?php endif; ?>
			</table>
		</td>
	</tr>
	<tr>
		<td>&nbsp;</td>
	</tr>    				
	<tr>
		<td class="table-heading" id="td-advance-search">Tìm kiếm nâng cao</td>
	</tr>
	<tr>
		<?php if($isSearchAdvance): ?>
		<td id="table-advance-search" class="tracuu">
		<?php else: ?>
		<td id="table-advance-search" style="display:none; padding:10px" class="tracuu">
		<?php endif; ?>
			<table width="100%" cellpadding="5" cellspacing="0">
				<tr>
					<td width="200">Nhóm văn bản</td>
					<td>
						<select name="catid">
							<option value="">-- Lựa chọn --</option>
							<?php echo JHtml::_('select.options', JHtml::_('category.options', 'com_skkn'), 'value', 'text', @$get['catid']);?>
						</select>
					</td>
				</tr>
				<tr>
					<td>Cơ quan ban hành</td>
					<td>
						<select name="org_id">
							<option value="">-- Lựa chọn --</option>
							<?php foreach ($this->orgs as $org): ?>
							
							<option value="<?php echo $org->id; ?>" <?php if($org->id == @$get['org_id']):?>selected<?php endif; ?>><?php echo $org->name; ?></option>
							<?php endforeach;?>
						</select>
					</td>
				</tr>
				<tr>
					<td>Thể loại</td>
					<td>
						<select name="type_id">
							<option value="">-- Lựa chọn --</option>
							<?php foreach ($this->types as $type): ?>
							<option value="<?php echo $type->id; ?>" <?php if($type->id == @$get['type_id']):?>selected<?php endif; ?>><?php echo $type->name; ?></option>
							<?php endforeach;?>
						</select>
					</td>
				</tr>
				<tr>
					<td>Loại công việc</td>
					<td>
						<select name="kind_id">
							<option value="">-- Lựa chọn --</option>
							<?php foreach ($this->working_kinds as $working_kind): ?>
							<option value="<?php echo $working_kind->id; ?>" <?php if($working_kind->id == @$get['kind_id']):?>selected<?php endif; ?>><?php echo $working_kind->name; ?></option>
							<?php endforeach;?>
						</select>
					</td>
				</tr>
				<tr>
					<td></td>
					<td><input class="button" type="button" value="Tìm kiếm" id="btn-advance-search" /></td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td>&nbsp;</td>
	</tr>
	<tr>
		<td class="table-heading">Thông tin văn bản</td>
	</tr>
	
	<tr>
		<td class="tracuu">
			<table width="100%" cellpadding="5" cellspacing="1" class="table-text-info">		
				<tr>
					<th>#</th>
					<th>Số hiệu</th>
					<th>Ngày ban hành</th>
					<th>Trích yếu</th>
					<th>Thể loại</th>
					<th>Cơ quan ban hành</th>
					<th>Tải về</th>
				</tr>
				
				<?php foreach($this->items as $key => $item): ?>
				<tr style="background:<?php if( ( $key + 1 ) % 2 == 0): ?>#EFEFEF<?php else: ?>#FFF<?php endif; ?>">
					<td><?php echo $key + 1; ?></td>
					<td>
						<a href='<?php echo JRoute::_('index.php?option=com_skkn&view=detail&id='.$item->id); ?>'>
							<strong><?php echo $item->text_code; ?></strong>
						</a>
					</td>
					<td>
						<?php 
						$tmpCreated = explode('-', $item->text_created);
						echo $tmpCreated[2].'/'.$tmpCreated[1].'/'.$tmpCreated[0]; 
						?>
					</td>
					<td><?php echo $item->description; ?></td>
					<td><?php echo $item->type_title; ?></td>
					<td><?php echo $item->org_title; ?></td>
					<td><a href='<?php echo JRoute::_(JURI::base().'index.php?option=com_skkn&task=download&file='.$item->text_file);?>'>
							<?php echo '<img src="'.JURI::base().'components/com_skkn/images/icon_download.gif" width="16" height="16" />'; ?>
					</a></td>
				</tr>
				<?php endforeach; ?>
				<?php if(!isset($key)): ?>
				<tr>
					<td colspan="8" style="padding: 10px;">Không tìm thấy bản ghi nào !</td>
				</tr>
				<?php endif; ?>
			</table>
		</td>
	</tr>
	
</table>

<div class="pagination">
	<?php echo $this->pagination->getPagesLinks(); ?>
</div>

<input type="hidden" name="is_search" value="1" />

</form>
